﻿@model Football.ViewModels.GameViewModel
<div id="player-list">
    <div class="clear-fix" id="whosin">
        @if (Model.HasActivePlayers)
        {
            <h3>
                Who's game?</h3>
        }
        else
        {
            <h3 id="no-one-yet">
                Nobody wants to meet the pain train yet!</h3>
        }
        @if (Model.HasInactivePlayers)
        { <mark id="show-the-quitters">Show the quitters!</mark>
            <mark id="hide-the-quitters">Hide the quitters!</mark>
        }
    </div>
    @if (Model.HasActivePlayers || Model.HasInactivePlayers)
    {
        <ol class="round">
            @foreach (var player in Model.GamePlayerList)
            {
                <li class="clear-fix @if (player.GamePlayer.GamePlayerStatusId == 1)
                                     {
                    @:in
                    }
                                     else
                                     {
                    @:out
                    }" 
                        id="@player.GamePlayer.GamePlayerId">
                    <div class="badgewrapper">
                        <span class="badge">
                            @if (player.GamePlayer.GamePlayerStatusId == 1)
                            {
                                @player.Index
                            }
                            else
                            {
                                @player.GamePlayer.GamePlayerStatuses.PlayerStatus
                            }</span>
                    </div>
                    <div class="playerwrapper">
                        <h5 class="playername">@player.GamePlayer.Name</h5>
                        <div class="playertime">
                        </div>
                    </div>
                    @if (player.GamePlayer.GamePlayerStatusId == 1)
                    {
                        @Html.ActionLink(
                    "x",
                    "ToggleStatus",
                    "Player",
                    new { id = player.GamePlayer.GamePlayerId },
                    new { @class = "close" }
                )
                    }
                </li>
            }
        </ol>
    }
</div>

    <script type="text/javascript">
        $(function () {

            $('#show-the-quitters').click(function () {
                $('#show-the-quitters').hide();
                $('#hide-the-quitters').show();
                $('.out').show();
            });

            $('#hide-the-quitters').click(function () {
                $('#hide-the-quitters').hide();
                $('#show-the-quitters').show();
                $('.out').hide();
            });

            $('.close').click(function () {

                var name = $(this).parent().find(".playername").text();

                if (confirm('Kick ' + name + ' from the game?')) {
                    $.post(this.href, function (json) {
                        $("#" + json.id).fadeTo("slow", 0.33);
                        $("#" + json.id + " .badge").text("Out");
                        $("#NewPlayerName").text('');
                        $("#" + json.id + " .close").text("");
                        $("#" + json.id).delay(3000).fadeOut(400, closeComplete);

                        function closeComplete() {
                            $.get('@Url.Action("PlayerList","Home", new { id = 1 } )', function (data) {
                                $('#player-list').replaceWith(data);
                            });
                        }
                    });
                }
                return false;
            });
        });
    </script>
